﻿function(add_all_suddir dir)
    cmake_parse_arguments(P_ARGS "" "ROOT_DIR;IGNORE_DIR" "CMAKE_ARGS" ${ARGN})
    file(GLOB_RECURSE LIST_G "${dir}/*CMakeLists.txt" )
    if(NOT P_ARGS_ROOT_DIR)
        set(P_ARGS_ROOT_DIR ${CMAKE_SOURCE_DIR})
    endif()
    # 移除根目录的CMakeLists.txt
    list(REMOVE_ITEM LIST_G "${P_ARGS_ROOT_DIR}/CMakeLists.txt")
    
    if(P_ARGS_IGNORE_DIR)
        # 移除忽略目录的CMakeLists.txt
        list(FILTER LIST_G EXCLUDE REGEX "${P_ARGS_IGNORE_DIR}/*CMakeLists.txt")
    endif()

    foreach(list_file ${LIST_G})
        cmake_path(GET list_file PARENT_PATH dir)
        add_subdirectory(${dir})
        message(STATUS "add directory: ${dir}")
    endforeach()
endfunction()